package xfuzzy.xfghl.model;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import xfuzzy.Xfuzzy;
import xfuzzy.lang.Specification;
import xfuzzy.xfghl.view.XfghlViewNew;

/**
 * Clase que representa el controlador de la herramienta en el patron Modelo-Vista-Controlador
 * @author Alberto David Fernandez Fernandez
 * */

public class XfghlControllerNew implements ActionListener {
	
	/**
	 * Instancia de la vista
	 * */
	private XfghlViewNew xfghlView;
	
	/**
	 * Constructor de la clase
	 * @param xfuzzy Instancia de la ventana principal 
	 * @param spec Especificacion elegida para la herramienta Xfghl
	 * */

	public XfghlControllerNew(Xfuzzy xfuzzy, Specification spec)  {
		
		xfghlView = new XfghlViewNew(this, xfuzzy, spec);
		xfghlView.setVisible(true);
	}
	
	/**
	 * Manejador de eventos
	 * @param arg0 Evento recibido
	 * */
	
	@Override
	public void actionPerformed(ActionEvent arg0) {

		String command = arg0.getActionCommand();

		if (command.equals("Run")) {
			this.xfghlView.run();
		} else if (command.equals("Close")) {
			this.xfghlView.dispose();
		} else if (command.equals("NewConfiguration")) {
			this.xfghlView.newConfiguration();
		} else if (command.equals("Save")) {
			this.xfghlView.saveSpecification();
		} else if (command.equals("Apply")) {
			this.xfghlView.apply();
		} else if (command.equals("EditConfiguration")) {
			this.xfghlView.editConfiguration();
		} else if (command.equals("Pause")) {
			xfghlView.pause();
		} else if (command.equals("Continue")) {
			xfghlView.contin();
		} else if (command.equals("Reload")) {
			xfghlView.reload();
		} else if (command.equals("LoadConfiguration")) {
			xfghlView.loadConfiguration();
		} else if (command.equals("SaveConfiguration")) {
			xfghlView.saveConfiguration();
		}
	}
}
